import 'package:flutter/material.dart';

class SpecialStatisticsPage extends StatelessWidget {
  final Map<String, List<bool>> dailyTasks;
  final List<String> taskTitles;

  const SpecialStatisticsPage({
    super.key, 
    required this.dailyTasks,
    required this.taskTitles,
  });

  String _dateToString(DateTime date) {
    return '${date.year}-${date.month}-${date.day}';
  }

  @override
  Widget build(BuildContext context) {
    // 获取过去90天的日期
    final List<DateTime> dates = List.generate(90, (index) {
      return DateTime.now().subtract(Duration(days: index));
    });

    // 获取"静坐"任务的索引
    final gratitudeIndex = taskTitles.indexOf('静坐');

    return Scaffold(
      appBar: AppBar(
        title: const Text('专项统计'),
        backgroundColor: Theme.of(context).colorScheme.primaryContainer,
      ),
      body: ListView.builder(
        itemCount: dates.length,
        itemBuilder: (context, index) {
          final date = dates[index];
          final dateKey = _dateToString(date);
          
          // 检查当天是否完成了静坐
          bool isGratitudeRecorded = false;
          if (dailyTasks.containsKey(dateKey) && gratitudeIndex != -1) {
            isGratitudeRecorded = dailyTasks[dateKey]![gratitudeIndex];
          }

          return Container(
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(
                  color: Colors.grey[200]!,
                  width: 1,
                ),
              ),
            ),
            child: ListTile(
              title: Row(
                children: [
                  // 日期显示
                  Text(
                    '${date.month}月${date.day}日',
                    style: const TextStyle(
                      fontSize: 16,
                    ),
                  ),
                  const Spacer(),
                  // 表情图标
                  Text(
                    isGratitudeRecorded ? '✅' : '❌',
                    style: const TextStyle(
                      fontSize: 24,
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}